// 子传父

import { useState } from 'react';
import { Button, Text, View } from 'react-native';
export default function App() {
  const [count, setCount] = useState(100);
  // 定义一个传递给子组件的函数
  const handleIncrementFn = () => {
    setCount(count + 1);
  };
  return (
    <View>
      <Text>我是父组件</Text>
      <Text>我是父组件</Text>
      <Text>我是父组件</Text>
      <Text>我是父组件</Text>
      <Text>{count}</Text>
      <Child count={count} handleIncrement={handleIncrementFn}></Child>
    </View>
  );
}
interface ChildProps {
  count: number;
  handleIncrement: () => void;
}

const Child = ({ count, handleIncrement }: ChildProps) => {
  return (
    <View>
      <Text>我是子组件</Text>
      <Text>{count}</Text>
      <Button
        title="点击增加计数"
        onPress={() => {
          // 调用父组件传递的函数
          handleIncrement();
        }}
      ></Button>
    </View>
  );
};
